package com.ruoyi.web.controller.chargeback.controller;


import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.charge.vo.BannerVo;
import com.ruoyi.charge.bo.BannerQueryBo;
import com.ruoyi.charge.bo.BannerAddBo;
import com.ruoyi.charge.bo.BannerEditBo;
import com.ruoyi.charge.service.IBannerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 广告管理Controller
 *
 * @author fanqie
 * @date 2021-10-28
 */
@Api(value = "广告管理控制器", tags = {"后台广告管理管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/back/banner")
public class BackBannerController extends BaseController {

    private final IBannerService iBannerService;

    /**
     * 查询广告管理列表
     */
    @ApiOperation("查询广告管理列表")
    @PreAuthorize("@ss.hasPermi('back:banner:list')")
    @GetMapping("/list")
    public TableDataInfo<BannerVo> list(BannerQueryBo bo) {
        startPage();
        List<BannerVo> list = iBannerService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出广告管理列表
     */
    @ApiOperation("导出广告管理列表")
    @PreAuthorize("@ss.hasPermi('back:banner:export')")
    @Log(title = "广告管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<BannerVo> export(BannerQueryBo bo) {
        List<BannerVo> list = iBannerService.queryList(bo);
        ExcelUtil<BannerVo> util = new ExcelUtil<BannerVo>(BannerVo.class);
        return util.exportExcel(list, "广告管理");
    }

    /**
     * 获取广告管理详细信息
     */
    @ApiOperation("获取广告管理详细信息")
    @PreAuthorize("@ss.hasPermi('back:banner:query')")
    @GetMapping("/{id}")
    public AjaxResult<BannerVo> getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(iBannerService.queryById(id));
    }

    /**
     * 新增广告管理
     */
    @ApiOperation("新增广告管理")
    @PreAuthorize("@ss.hasPermi('back:banner:add')")
    @Log(title = "广告管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody BannerAddBo bo) {
        return toAjax(iBannerService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改广告管理
     */
    @ApiOperation("修改广告管理")
    @PreAuthorize("@ss.hasPermi('back:banner:edit')")
    @Log(title = "广告管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody BannerEditBo bo) {
        return toAjax(iBannerService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除广告管理
     */
    @ApiOperation("删除广告管理")
    @PreAuthorize("@ss.hasPermi('back:banner:remove')")
    @Log(title = "广告管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@PathVariable Long[] ids) {
        return toAjax(iBannerService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
